package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.album.AlbumInfoIndexSearchVo;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 专辑上架
     * @param albumId
     * @return
     */
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        searchService.upperAlbum(albumId);
        return Result.ok();
    }


    /**
     * 专辑下架
     * @param albumId
     * @return
     */
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }


    ///api/search/albumInfo/batchUpperAblum
    @GetMapping("/batchUpperAblum")
    public Result batchUpperAblum(){
        for (int i = 150; i < 1000; i++) {
            searchService.upperAlbum(Long.parseLong(String.valueOf(i)));
        }
        return Result.ok();
    }

    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo =searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }


    /**
     * 获取频道页数据
     * @param category1Id
     * @return
     */
    @GetMapping("/channel/{category1Id}")
    public Result<List<AlbumInfoIndexSearchVo>> channel(@PathVariable Long category1Id){
        List<AlbumInfoIndexSearchVo> albumInfoIndexSearchVo = searchService.channel(category1Id);
        return Result.ok(albumInfoIndexSearchVo);
    }


    /**
     * 搜索自动补全
     * @param keyword
     * @return
     */
    @GetMapping("/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword){
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    /**
     * 更新排行耪
     * @return
     */
    @GetMapping("/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }


    /**
     * 获取排行榜数据
     * @param category1Id
     * @param dimension
     * @return
     */
    @GetMapping("/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id, @PathVariable String dimension){
        List<AlbumInfoIndexVo> list =searchService.findRankingList(category1Id,dimension);
        return Result.ok(list);
    }
}

